from collections import deque

n = int(input())
nums = []
for _ in range(n):
    nums.append(tuple(map(int, input().split())))

nums.sort(key=lambda x:x[0]-x[1])
q = deque(nums)
damage = 0
cnt = 0
while q:
    last = q.pop()
    cnt += 1
    damage += last[1]
    while q and damage >= q[0][0]:
        damage += q.popleft()[1]
print(cnt)
